<template>
  <view class="reward-container">
    <!-- 背景装饰 -->
   
    
    <!-- 主要内容区 -->
    <view class="content">
      <!-- 弹窗 -->
      <view class="popup">
        <!-- 弹窗头部 -->
        <view class="popup-header">
          <text class="header-dot">🍃</text>
          <text class="popup-title">静待风来</text>
          <text class="header-dot">🍃</text>
        </view>
        
        <!-- 弹窗内容 -->
        <view class="popup-content">
          <!-- 金币图标 -->
          <view class="image-container">
            <img :src="imgUrl" class="reward-image">
          </view>
          
          <!-- 信息显示区域 -->
          <view class="info-display-area">
            <!-- 第一行 -->
            <view class="info-row">
              <text class="info-label">本次事件年利率:</text>
              <view class="info-value">{{ interestRate }}</view>
            </view>
            
            <!-- 第二行 -->
            <view class="info-row">
              <text class="info-label">当前年龄:</text>
              <view class="info-value">{{ currentAge }}岁</view>
            </view>
            
            <!-- 第三行 -->
            <view class="info-row">
              <text class="info-label">当前储蓄:</text>
              <view class="info-value">{{ currentSavings }}</view>
            </view>
          </view>
        </view>
        
        <!-- 弹窗底部 -->
        <view class="popup-footer">
          <button class="accept-button" @tap="continueSimulation">继续模拟</button>
        </view>
      </view>
    </view>
    
    <!-- 底部功能按钮 -->
    
    <!-- 跳出弹窗 -->
    <view class="modal-container" v-if="showModalFlag">
      <view class="modal-backdrop" @tap="closeModal"></view>
      <view class="modal-content">
        <!-- 黑色圆形关闭按钮 -->
        <view class="close-button" @tap="closeModal">
          <text class="close-icon">×</text>
        </view>
        
        <!-- 弹窗图片内容 -->
        <view class="modal-image-container">
          <img :src="dead ? deathImage : '/static/die/one.jpg'" class="modal-image">
        </view>
        
        <!-- 弹窗文字内容 -->
        <view class="modal-action">
          <button class="go-to-leaderboard-button" @tap="goToLeaderboard">查看排行榜</button>
        </view>
      </view>
    </view>
    
    <!-- 退休金弹窗 -->
    <view class="retirement-modal" v-if="showRetirementModal && !dead">
      <view class="modal-content">
        <view class="modal-close" @tap="closeRetirementModal">×</view>
         <view class="modal-title">退休啦</view>
         <view class="modal-text">
           哇哦，从现在开始，您每年都有一笔丰厚的退休金可以领啦！
         </view>
        <button class="modal-button" @tap="startRetirementLife">开启退休生活</button>
      </view>
    </view>

  </view>
</template>

<script>
export default {
  data() {
    return {
      // 存储从参数中获取的数据
      interestRate: '0.00%',
      currentAge: '0',
      currentSavings: '¥0.00',
      imgUrl: '/static/deficit/bank_deposit_loss.jpg',
      showModalFlag: false,
      dead: false,
      deathDescription: '',
      deathImage: '',
      hasRetirementBonus: false,
      showRetirementModal: false
    };
  },
  onLoad(options) {
    // 页面加载时获取传递的参数
    if (options.data) {
      try {
        const data = JSON.parse(decodeURIComponent(options.data));
        this.interestRate = data.interestRate || '0.00%';
        this.currentAge = data.currentAge || '0';
        this.currentSavings = data.currentSavings ? '¥' + parseFloat(data.currentSavings).toFixed(2) : '¥0.00';
        this.imgUrl = data.imgUrl || '/static/deficit/bank_deposit_loss.jpg';
        this.dead = data.dead || false;
        this.deathDescription = data.deathDescription || '';
        this.deathImage = data.deathImage || '';
        this.hasRetirementBonus = data.hasRetirementBonus || false;
      } catch (e) {
        console.error('解析参数失败:', e);
      }
    }
  },
  methods: {
    // 接受奖励
    acceptReward() {
      // 这里可以添加领取奖励的逻辑
      uni.showToast({
        title: '领取成功！',
        icon: 'success',
        duration: 1500
      });
      
      // 存储奖励到本地
      uni.setStorageSync('hasReceivedReward', true);
      
      // 可以添加领取后的跳转逻辑
      setTimeout(() => {
        // 例如跳转到首页
        // uni.navigateTo({ url: '/pages/index/index' });
      }, 1500);
    },
    
    // 继续模拟
    continueSimulation() {
      // 如果当前余额为0，直接跳转到排行榜
      if (parseFloat(this.currentSavings.replace('¥', '')) === 0) {
        uni.redirectTo({ url: '/pages/simulator/leaderboard' });
        return;
      }
      
      // 只有当hasRetirementBonus为true时才显示退休金弹窗
      if (this.hasRetirementBonus) {
        this.showRetirementModal = true;
      } else if (this.dead) {
        // 如果已死亡则显示弹窗
        this.showModalFlag = true;
      } else {
        // 否则跳转到风险选择页面
        uni.redirectTo({ url: '/pages/simulator/risk-select' });
      }
    },
    
    // 关闭退休金弹窗
    closeRetirementModal() {
      this.showRetirementModal = false;
    },
    
    // 开启退休生活
    startRetirementLife() {
      this.showRetirementModal = false;
      // 如果已经死亡，则跳转到排行榜页面
      if (this.dead) {
        uni.redirectTo({ url: '/pages/simulator/leaderboard' });
      } else {
        // 否则跳转到风险选择页面
        uni.redirectTo({ url: '/pages/simulator/risk-select' });
      }
    },
    
    // 关闭弹窗
    closeModal() {
      this.showModalFlag = false;
    },
    
    // 跳转到排行榜页面
    goToLeaderboard() {
      // 关闭弹窗
      this.closeModal();
      // 跳转到排行榜页面，使用 redirectTo 替换当前页面
      uni.redirectTo({ url: '/pages/simulator/leaderboard' });
    }
  }
};
</script>

<style scoped>
/* 主容器 */
.reward-container {
  position: relative;
  min-height: 100vh;
  /* 使用从上到下的蓝色到白色渐变背景 */
  background: linear-gradient(to bottom, #E3F2FD, #FFFFFF);
  display: flex;
  flex-direction: column;
  padding: 20rpx;
  box-sizing: border-box;
}

/* 背景装饰 */
.background-decoration {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  opacity: 0.6;
}

/* 窗户 */
.window {
  position: absolute;
  top: 100rpx;
  left: 50%;
  transform: translateX(-50%);
  width: 600rpx;
  height: 300rpx;
}

.window-frame {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 12rpx solid #8B4513;
  border-radius: 20rpx 20rpx 0 0;
  background-color: #87CEEB;
}

.window-glass {
  position: absolute;
  top: 12rpx;
  left: 12rpx;
  width: calc(100% - 24rpx);
  height: calc(100% - 24rpx);
  background-color: rgba(145, 224, 255, 0.3);
}

.curtain {
  position: absolute;
  top: 12rpx;
  height: 160rpx;
  background-color: #F08080;
}

.curtain.left {
  left: 12rpx;
  width: 250rpx;
  border-radius: 0 10rpx 10rpx 0;
}

.curtain.right {
  right: 12rpx;
  width: 250rpx;
  border-radius: 10rpx 0 0 10rpx;
}

/* 礼物盒 */
.gift-box {
  position: absolute;
  top: 340rpx;
  width: 120rpx;
  height: 120rpx;
  background-color: #FF6B6B;
  border: 8rpx solid #FF4444;
}

.gift-box.left {
  left: 100rpx;
}

.gift-box.right {
  right: 100rpx;
}

.gift-box::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: 20rpx;
  background-color: #FF4444;
  transform: translateY(-50%);
}

.gift-box::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 0;
  width: 20rpx;
  height: 100%;
  background-color: #FF4444;
  transform: translateX(-50%);
}

/* 主要内容区 */
.content {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1;
  padding-bottom: 100rpx;
  position: relative;
}

/* 弹窗 */
.popup {
  width: 800rpx;
  /* 使用白色和浅蓝色的渐变背景 */
  background: linear-gradient(135deg, #FFFFFF, #F0F8FF);
  border: 4rpx solid #BBDEFB;
  border-radius: 30rpx;
  /* 增强阴影效果，提高立体感 */
  box-shadow: 0 0 40rpx rgba(0, 0, 0, 0.1), 0 20rpx 40rpx rgba(0, 0, 0, 0.05);
  overflow: hidden;
  position: relative;
}

/* 弹窗头部 */
.popup-header {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20rpx;
  padding: 30rpx 0;
  /* 使用浅蓝色渐变背景 */
  background: linear-gradient(135deg, #E3F2FD, #BBDEFB);
  border-bottom: 2rpx solid #90CAF9;
}

.header-dot {
  font-size: 36rpx;
  color: #1976D2;
}

.popup-title {
  font-size: 36rpx;
  font-weight: bold;
  /* 使用深蓝色文字，确保在浅色背景下清晰可读 */
  color: #0D47A1;
  text-shadow: 0 1rpx 2rpx rgba(255, 255, 255, 0.5);
}

/* 弹窗内容 */
.popup-content {
  padding: 5rpx;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10rpx;
}

/* 图片容器 */
.image-container {
  width: 100%;
  padding: 10rpx;
  margin: 0;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 500rpx;
  /* 使用白色和浅蓝色渐变背景 */
  background: linear-gradient(135deg, #FFFFFF, #E3F2FD);
  border-radius: 20rpx;
  border: 2rpx solid #BBDEFB;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
}

/* 金币图标 */
.coin-icon {
  margin-bottom: 30rpx;
}

.coins {
  font-size: 120rpx;
  display: block;
  animation: coinShake 1s ease-in-out infinite;
}

/* 奖励图片 */
.reward-image {
  width: 100%;
  height: auto;
  display: block;
  max-width: 100%;
  max-height: none;
  height: 500rpx;
  object-fit: contain;
  margin: 0 auto;
  padding: 0;
  z-index: 10;
}

/* 金币动画 */
@keyframes coinShake {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
}

/* 信息显示区域 */
.info-display-area {
  width: 100%;
  /* 使用白色和浅蓝色渐变背景 */
  background: linear-gradient(135deg, #FFFFFF, #F5F9FF);
  border: 2rpx solid #BBDEFB;
  border-radius: 20rpx;
  padding: 20rpx;
  margin: 0;
  box-sizing: border-box;
  flex-shrink: 0;
  /* 添加柔和阴影，增强层次感 */
  box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
}

/* 信息行 */
.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15rpx;
  padding: 10rpx 0;
  border-bottom: 2rpx solid #F5F5DC;
  box-sizing: border-box;
}

.info-row:last-child {
  margin-bottom: 0;
  border-bottom: none;
}

/* 信息标签 */
.info-label {
  font-size: 28rpx;
  /* 使用深蓝色文字，确保在浅色背景下清晰可读 */
  color: #1565C0;
  font-weight: bold;
  flex: 0 0 auto;
  margin-right: 10rpx;
  white-space: nowrap;
}

/* 信息值显示框 */
.info-value {
  font-size: 28rpx;
  /* 使用深蓝色文字，确保在浅色背景下清晰可读 */
  color: #0D47A1;
  font-weight: bold;
  /* 使用浅蓝色背景 */
  background-color: #E3F2FD;
  border: 2rpx solid #90CAF9;
  border-radius: 10rpx;
  padding: 8rpx 15rpx;
  flex: 0 0 auto;
  min-width: 120rpx;
  text-align: right;
  box-sizing: border-box;
}

/* 弹窗底部 */
.popup-footer {
  padding: 30rpx 40rpx;
  /* 使用浅蓝色渐变背景 */
  background: linear-gradient(135deg, #E3F2FD, #BBDEFB);
  border-top: 2rpx solid #90CAF9;
}

/* 接受按钮 */
.accept-button {
  width: 100%;
  height: 96rpx;
  /* 使用蓝色渐变背景，增强视觉效果 */
  background: linear-gradient(135deg, #1976D2, #2196F3);
  color: white;
  font-size: 36rpx;
  font-weight: bold;
  border-radius: 48rpx;
  border: none;
  transition: all 0.3s;
  position: relative;
  overflow: hidden;
  /* 添加阴影，增强立体感 */
  box-shadow: 0 4rpx 12rpx rgba(25, 118, 210, 0.3);
  text-shadow: 0 1rpx 2rpx rgba(0, 0, 0, 0.3);
}

.accept-button:active {
  transform: scale(0.98);
  /* 点击时颜色变深 */
  background: linear-gradient(135deg, #1565C0, #1976D2);
}

.accept-button::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 100%;
  background-color: rgba(255, 255, 255, 0.3);
  transition: all 0.3s;
  transform: translate(-50%, -50%);
}

.accept-button:active::before {
  width: 100%;
}



/* 底部功能按钮 */
.bottom-actions {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 120rpx;
  background-color: #FFF;
  display: flex;
  justify-content: space-around;
  align-items: center;
  box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.1);
  z-index: 2;
}

.action-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10rpx;
}

.action-icon {
  font-size: 48rpx;
  margin-bottom: 8rpx;
}

.action-text {
  font-size: 24rpx;
  color: #666;
}

/* 跳出弹窗样式 */
.modal-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
  position: relative;
  width: 80%;
  max-width: 700rpx;
  background: white;
  border-radius: 30rpx;
  padding: 40rpx;
  box-shadow: 0 0 60rpx rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* 黑色圆形关闭按钮 */
.close-button {
  position: absolute;
  top: -30rpx;
  right: -30rpx;
  width: 60rpx;
  height: 60rpx;
  border-radius: 50%;
  background-color: #000000;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.2);
  z-index: 1001;
}

.close-icon {
  color: white;
  font-size: 40rpx;
  font-weight: bold;
  line-height: 1;
}

/* 弹窗图片容器 */
.modal-image-container {
  width: 100%;
  height: 500rpx;
  margin-bottom: 0rpx;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* 死亡描述 */
.death-description {
  font-size: 32rpx;
  color: #DAA520;
  padding: 20rpx 30rpx;
  text-align: center;
  line-height: 1.6;
}

/* 弹窗图片 */
.modal-image {
  width: 105%;
  height: 100%;
  object-fit: contain;
  border-radius: 20rpx;
}

/* 弹窗操作区域 */
.modal-action {
  text-align: center;
  margin-top: 20rpx;
  width: 100%;
}

/* 排行榜按钮 */
.go-to-leaderboard-button {
  width: 100%;
  height: 90rpx;
  background: linear-gradient(135deg, #000000 0%, #000000 100%);
  color: white;
  font-size: 36rpx;
  font-weight: bold;
  border-radius: 45rpx;
  border: none;
  transition: all 0.3s;
  box-shadow: 0 4rpx 12rpx rgba(79, 172, 254, 0.3);
  text-shadow: 0 1rpx 2rpx rgba(0, 0, 0, 0.3);
}

.go-to-leaderboard-button:active {
  transform: scale(0.98);
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 80%);
}

/* 动画效果 */
@keyframes modalFadeIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.modal-content {
  animation: modalFadeIn 0.3s ease-out;
}

/* 退休金弹窗样式 */
.retirement-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.retirement-modal .modal-content {
  position: relative;
  width: 80%;
  max-width: 700rpx;
  background: white;
  border-radius: 30rpx;
  padding: 40rpx;
  text-align: center;
  position: relative;
  box-shadow: 0 20rpx 40rpx rgba(0, 0, 0, 0.2);
  animation: modalFadeIn 0.3s ease-out;
}

.modal-close {
  position: absolute;
  top: 20rpx;
  right: 20rpx;
  width: 60rpx;
  height: 60rpx;
  font-size: 48rpx;
  color: #999;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  background-color: #f5f5f5;
}

.modal-title {
    font-size: 55rpx;
    font-weight: bold;
    color: #FF9800;
    margin: 20rpx 0;
    text-align: center;
  }
  
  .modal-text {
    font-size: 34rpx;
    color: #333;
    line-height: 1.8;
    margin: 40rpx 0;
  }

.modal-button {
  width: 100%;
  height: 90rpx;
  background-color: #ffc165;
  color: white;
  font-size: 36rpx;
  font-weight: bold;
  border-radius: 45rpx;
  border: none;
  margin-top: 20rpx;
}

.modal-button:active {
  background-color: #F57C00;
}
</style>
